{% extends base %}

{% block init_vars_block %}
    {% init show_right = False %}
{% end %}

{% block head %}
    <script type="text/javascript" src="{{_server_home}}/_static/lib/utf.js/utf-v1.0.js"></script>
{% end %}

{% block body %}

<div class="card">
    {% set title = "Base64编解码" %}
    {% include "common/title/base_title.html" %}
</div>

{% include tools/text_tab.html %}

<div class="card">
    <div class="row">
        <label>Input</label>
        <textarea id="input" class="col-md-12" rows=10></textarea>
    </div>
    
    <div class="col-md-12 top-offset-1">
        <button class="btn" onclick="base64Encode()">Encode</button>
        <button class="btn" onclick="base64Decode()">Decode</button>
    </div>

</div>

<div class="card">
    <div class="row">
        <label>Output</label>
        <textarea id="output" class="col-md-12" rows=10></textarea>
    </div>
</div>

<script>
function base64Encode() {
    var bytes = utf16to8($("#input").val());
    $("#output").val(btoa(bytes));
}

function base64Decode() {
    try {
        var chars = atob($("#input").val());
        var str = utf8to16(chars);
        $("#output").val(str);
    } catch (e) {
        $("#output").val("");
        xnote.alert("" + e);
    }
}
</script>
{% end %}